package com.tbeasy.financial.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.tbeasy.financial.R;

public class AddTranscationCurrencyView extends LinearLayout {

	private Context mContext;
	private LinearLayout parentView;
	private ImageView arrowImageView;
	private ImageView typeIncomeImageView;
	private ImageView typePayoutImageView;
	private Button keyboardNumber1Btn;
	private Button keyboardNumber2Btn;
	private Button keyboardNumber3Btn;
	private Button keyboardNumber4Btn;
	private Button keyboardNumber5Btn;
	private Button keyboardNumber6Btn;
	private Button keyboardNumber7Btn;
	private Button keyboardNumber8Btn;
	private Button keyboardNumber9Btn;
	private Button keyboardNumber0Btn;
	private Button keyboardClearBtn;
	private Button keyboardDotBtn;
	private Button keyboardAddBtn;
	private Button keyboardSubtractBtn;
	private Button keyboardOkBtn;

	private Animation showAction;
	private Animation hideAction;

	public AddTranscationCurrencyView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.input_view, this);
		initView();
	}

	public AddTranscationCurrencyView(Context context) {
		this(context, null);
	}

	private void initView() {
		parentView = (LinearLayout) findViewById(R.id.input_root);
		// parentView.setVisibility(View.GONE);
		arrowImageView = (ImageView) findViewById(R.id.input_keyboard_arrow);
		typeIncomeImageView = (ImageView) findViewById(R.id.input_keyboard_type_income);
		typePayoutImageView = (ImageView) findViewById(R.id.input_keyboard_type_payout);
		keyboardAddBtn = (Button) findViewById(R.id.input_keyboard_btn_add);
		keyboardDotBtn = (Button) findViewById(R.id.input_keyboard_btn_dot);
		keyboardSubtractBtn = (Button) findViewById(R.id.input_keyboard_btn_subtract);
		keyboardOkBtn = (Button) findViewById(R.id.input_keyboard_btn_ok);
		keyboardClearBtn = (Button) findViewById(R.id.input_keyboard_btn_clear);
		keyboardNumber0Btn = (Button) findViewById(R.id.input_keyboard_btn_0);
		keyboardNumber1Btn = (Button) findViewById(R.id.input_keyboard_btn_1);
		keyboardNumber2Btn = (Button) findViewById(R.id.input_keyboard_btn_2);
		keyboardNumber3Btn = (Button) findViewById(R.id.input_keyboard_btn_3);
		keyboardNumber4Btn = (Button) findViewById(R.id.input_keyboard_btn_4);
		keyboardNumber5Btn = (Button) findViewById(R.id.input_keyboard_btn_5);
		keyboardNumber6Btn = (Button) findViewById(R.id.input_keyboard_btn_6);
		keyboardNumber7Btn = (Button) findViewById(R.id.input_keyboard_btn_7);
		keyboardNumber8Btn = (Button) findViewById(R.id.input_keyboard_btn_8);
		keyboardNumber9Btn = (Button) findViewById(R.id.input_keyboard_btn_9);

		arrowImageView.setOnClickListener(clickListener);
		typeIncomeImageView.setOnClickListener(clickListener);
		typePayoutImageView.setOnClickListener(clickListener);
		keyboardAddBtn.setOnClickListener(clickListener);
		keyboardDotBtn.setOnClickListener(clickListener);
		keyboardSubtractBtn.setOnClickListener(clickListener);
		keyboardOkBtn.setOnClickListener(clickListener);
		keyboardClearBtn.setOnClickListener(clickListener);
		keyboardNumber0Btn.setOnClickListener(clickListener);
		keyboardNumber1Btn.setOnClickListener(clickListener);
		keyboardNumber2Btn.setOnClickListener(clickListener);
		keyboardNumber3Btn.setOnClickListener(clickListener);
		keyboardNumber4Btn.setOnClickListener(clickListener);
		keyboardNumber5Btn.setOnClickListener(clickListener);
		keyboardNumber6Btn.setOnClickListener(clickListener);
		keyboardNumber7Btn.setOnClickListener(clickListener);
		keyboardNumber8Btn.setOnClickListener(clickListener);
		keyboardNumber9Btn.setOnClickListener(clickListener);

		hideAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
				Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f);
		hideAction.setDuration(500);
		hideAction.setFillAfter(true);
		hideAction.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				parentView.setVisibility(View.GONE);
			}
		});

		showAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
				Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
		showAction.setFillAfter(true);
		showAction.setDuration(300);
		showAction.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				parentView.setVisibility(View.INVISIBLE);
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				parentView.setVisibility(View.VISIBLE);
			}
		});
	}

	private OnClickListener clickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.input_keyboard_arrow:
				dismiss();
				break;

			case R.id.input_keyboard_type_income:

				break;
			case R.id.input_keyboard_type_payout:

				break;
			case R.id.input_keyboard_btn_add:

				break;
			case R.id.input_keyboard_btn_dot:

				break;
			case R.id.input_keyboard_btn_subtract:

				break;
			case R.id.input_keyboard_btn_ok:

				break;
			case R.id.input_keyboard_btn_0:

				break;
			case R.id.input_keyboard_btn_1:

				break;
			case R.id.input_keyboard_btn_2:

				break;
			case R.id.input_keyboard_btn_3:

				break;
			case R.id.input_keyboard_btn_4:

				break;
			case R.id.input_keyboard_btn_5:

				break;
			case R.id.input_keyboard_btn_6:

				break;
			case R.id.input_keyboard_btn_7:

				break;
			case R.id.input_keyboard_btn_8:

				break;

			case R.id.input_keyboard_btn_9:

				break;

			}
		}
	};

	public void show() {
		if (parentView.getVisibility() == View.GONE) {
			parentView.startAnimation(showAction);
		}
	}

	public void dismiss() {
		if (parentView.getVisibility() == View.VISIBLE) {
			parentView.startAnimation(hideAction);
		}
	}

	public void setEditTextView(EditText view) {

	}
}
